package com.example.xianji.activity;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.adapter.ZiXun_Skill_Adapter;
import com.example.xianji.BGARefresh.BGANormalRefreshViewHolder;
import com.example.xianji.BGARefresh.BGARefreshLayout;
import com.example.xianji.BGARefresh.BGARefreshLayout.BGARefreshLayoutDelegate;
import com.example.xianji.bean.Collection;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.os.Bundle;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Main_My_product_liuyanActivity extends Activity implements BGARefreshLayoutDelegate {
    /**
     * 我对产品,服务，店铺留言列表
     * 我收到的产品，服务，店铺留言列表
     */
    private RelativeLayout relative_my_product_liuyan_back;
    private BGARefreshLayout my_product_liuyan_BGARefreshLayout;
    private ListView my_product_liuyan_listview;
    //    private SharedPreferences sp;
//    private Editor ed;
    private ArrayList<Collection> list = new ArrayList<Collection>();
    private ZiXun_Skill_Adapter mZiXun_Skill_Adapter;
    private int page = 1;
    private TextView liuyan_title;
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                my_product_liuyan_listview.setAdapter(mZiXun_Skill_Adapter);
                my_product_liuyan_BGARefreshLayout.endRefreshing();
            }
            if (msg.what == 2) {
                mZiXun_Skill_Adapter.notifyDataSetChanged();
                my_product_liuyan_BGARefreshLayout.endLoadingMore();
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main__my_product_liuyan);
//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();

        relative_my_product_liuyan_back = (RelativeLayout) findViewById(R.id.relative_my_product_liuyan_back);
        my_product_liuyan_BGARefreshLayout = (BGARefreshLayout) findViewById(R.id.my_product_liuyan_BGARefreshLayout);

        my_product_liuyan_listview = (ListView) findViewById(R.id.my_product_liuyan_listview);
        liuyan_title = (TextView) findViewById(R.id.liuyan_title);

        my_product_liuyan_BGARefreshLayout.setDelegate(this);
        my_product_liuyan_BGARefreshLayout.setRefreshViewHolder(new BGANormalRefreshViewHolder(this, true));
        if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_product_liuyan) {
            //我对产品的留言
            mZiXun_Skill_Adapter = new ZiXun_Skill_Adapter(this, list, Contant.come_from_my_product_liuyan);
            get_product_liuyan_data();
            liuyan_title.setText("我的留言");
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_service_liuyan) {
            //我对服务的留言
            mZiXun_Skill_Adapter = new ZiXun_Skill_Adapter(this, list, Contant.come_from_my_service_liuyan);
            get_service_liuyan_data();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_qiye_liuyan) {
            //我对店铺留言
            mZiXun_Skill_Adapter = new ZiXun_Skill_Adapter(this, list, Contant.come_from_my_qiye_liuyan);
            get_qiye_liuyan_data();
            liuyan_title.setText("我的留言");
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_fuwu_liuyan) {
            //企业账号：我收到的服务留言
            mZiXun_Skill_Adapter = new ZiXun_Skill_Adapter(this, list, Contant.come_from_my_receiver_fuwu_liuyan);
            get_myreceiver_fuwu_liuyan_data();
            liuyan_title.setText("我收到的留言");
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_qiye_liuyan) {
            //企业账号：我收到的店铺留言
            mZiXun_Skill_Adapter = new ZiXun_Skill_Adapter(this, list, Contant.come_from_my_receiver_qiye_liuyan);
            get_myreceiver_qiye_liuyan_data();
            liuyan_title.setText("我收到的留言");
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_product_liuyan) {
            //企业账号：我收到的产品留言
            mZiXun_Skill_Adapter = new ZiXun_Skill_Adapter(this, list, Contant.come_from_my_receiver_product_liuyan);
            get_myreceiver_product_liuyan_data();
            liuyan_title.setText("我收到的留言");
        }


        relative_my_product_liuyan_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Main_My_product_liuyanActivity.this.finish();
            }
        });
    }

    @Override
    public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
        page = 1;
        if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_product_liuyan) {
            //我对产品留言
            get_product_liuyan_data();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_service_liuyan) {
            //我对服务留言
            get_service_liuyan_data();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_qiye_liuyan) {
            //我对店铺的留言
            get_qiye_liuyan_data();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_fuwu_liuyan) {
            //企业账号：我收到的服务留言

            get_myreceiver_fuwu_liuyan_data();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_qiye_liuyan) {
            //企业账号：我收到的店铺留言
            get_myreceiver_qiye_liuyan_data();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_product_liuyan) {
            //企业账号：我收到的产品留言
            get_myreceiver_product_liuyan_data();
        }
    }

    @Override
    public boolean onBGARefreshLayoutBeginLoadingMore(
            BGARefreshLayout refreshLayout) {
        if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_product_liuyan) {
            get_product_liuyan_data_more();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_service_liuyan) {
            get_fuwu_liuyan_data_more();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_qiye_liuyan) {
            //我对店铺的留言
            get_qiye_liuyan_data_more();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_fuwu_liuyan) {
            //企业账号：我收到的服务留言
            get_myreceiver_fuwu_liuyan_data_more();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_qiye_liuyan) {
            //企业账号：我收到的服务留言
            get_myreceiver_qiye_data_more();
        } else if (getIntent().getIntExtra("liuyan_comeFrom", 0) == Contant.come_from_my_receiver_product_liuyan) {
            //企业账号：我收到的产品留言
            get_myreceiver_product_data_more();
        }
        return true;
    }

    /**
     * 产品留言
     */
    public void get_product_liuyan_data() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        parms.addBodyParameter("page", 1 + "");
        httpUtils.send(HttpMethod.POST, Contant.my_product_liuyan, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                        my_product_liuyan_BGARefreshLayout.endRefreshing();
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject response = new JSONObject(arg0.result);
                            if (response.getInt("status") == 1) {
                                list.clear();
                                JSONArray array = response.getJSONArray("data");
                                for (int i = 0; i < array.length(); i++) {
                                    JSONObject obj = array.getJSONObject(i);
                                    Collection mCollection = new Collection();
                                    mCollection.setTitle(obj.getJSONObject("boothsproduct").getString("title"));
                                    mCollection.setCreated_at(obj.getString("created_at"));
                                    mCollection.setDetail(obj.getString("detail"));
                                    mCollection.setNickname(obj.getJSONObject("other").getString("nickname"));
                                    mCollection.setId(obj.getInt("product_id"));
                                    list.add(mCollection);
                                }
                            }
                            handler.sendEmptyMessage(1);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    public void get_product_liuyan_data_more() {
        page++;
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();

        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        parms.addBodyParameter("page", page + "");

        httpUtils.send(HttpMethod.POST, Contant.my_product_liuyan, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                        my_product_liuyan_BGARefreshLayout.endLoadingMore();
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject response = new JSONObject(arg0.result);
                            if (response.getInt("status") == 1) {

                                JSONArray array = response.getJSONArray("data");
                                if (array.length() == 0) {
                                    Toast.makeText(Main_My_product_liuyanActivity.this, "没有更多数据哦", Toast.LENGTH_SHORT).show();
                                    my_product_liuyan_BGARefreshLayout.endLoadingMore();
                                } else {
                                    for (int i = 0; i < array.length(); i++) {
                                        JSONObject obj = array.getJSONObject(i);

                                        Collection mCollection = new Collection();

                                        mCollection.setTitle(obj.getJSONObject("boothsproduct").getString("title"));
                                        mCollection.setCreated_at(obj.getString("created_at"));
                                        mCollection.setDetail(obj.getString("detail"));
                                        mCollection.setNickname(obj.getJSONObject("other").getString("nickname"));
                                        mCollection.setId(obj.getInt("product_id"));
                                        list.add(mCollection);
                                    }
                                }
                                handler.sendEmptyMessage(2);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    /**
     * 我的服务留言
     */
    public void get_service_liuyan_data() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        parms.addBodyParameter("page", 1 + "");
        httpUtils.send(HttpMethod.POST, Contant.my_fuwu_liuyan, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                        my_product_liuyan_BGARefreshLayout.endRefreshing();
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject response = new JSONObject(arg0.result);
                            if (response.getInt("status") == 1) {
                                list.clear();
                                JSONArray array = response.getJSONArray("data");
                                for (int i = 0; i < array.length(); i++) {
                                    JSONObject obj = array.getJSONObject(i);
                                    Collection mCollection = new Collection();
                                    mCollection.setTitle(obj.getJSONObject("boothscase").getString("title"));
                                    mCollection.setCreated_at(obj.getString("created_at"));
                                    mCollection.setDetail(obj.getString("detail"));
                                    mCollection.setNickname(obj.getJSONObject("other").getString("nickname"));
                                    mCollection.setId(obj.getInt("case_id"));
                                    list.add(mCollection);
                                }
                            }
                            handler.sendEmptyMessage(1);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    public void get_fuwu_liuyan_data_more() {
        page++;
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();

        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        parms.addBodyParameter("page", page + "");

        httpUtils.send(HttpMethod.POST, Contant.my_fuwu_liuyan, parms,
                new RequestCallBack<String>() {
                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                        my_product_liuyan_BGARefreshLayout.endLoadingMore();
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject response = new JSONObject(arg0.result);
                            if (response.getInt("status") == 1) {
                                JSONArray array = response.getJSONArray("data");
                                if (array.length() == 0) {
                                    Toast.makeText(Main_My_product_liuyanActivity.this, "没有更多数据哦", Toast.LENGTH_SHORT).show();
                                    my_product_liuyan_BGARefreshLayout.endLoadingMore();
                                } else {
                                    for (int i = 0; i < array.length(); i++) {
                                        JSONObject obj = array.getJSONObject(i);
                                        Collection mCollection = new Collection();
                                        mCollection.setTitle(obj.getJSONObject("boothscase").getString("title"));
                                        mCollection.setCreated_at(obj.getString("created_at"));
                                        mCollection.setDetail(obj.getString("detail"));
                                        mCollection.setNickname(obj.getJSONObject("other").getString("nickname"));
                                        mCollection.setId(obj.getInt("case_id"));
                                        list.add(mCollection);
                                    }
                                }
                                handler.sendEmptyMessage(2);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    /**
     * 给企业留言
     */
    public void get_qiye_liuyan_data() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("page", 1);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_qiye_liuyan,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            Collection mCollection = new Collection();
                            mCollection.setTitle(obj.getJSONObject("booths").getString("title"));
                            mCollection.setCreated_at(obj.getString("created_at"));
                            mCollection.setDetail(obj.getString("detail"));
                            mCollection.setNickname(obj.getJSONObject("other").getString("nickname"));
                            mCollection.setId(obj.getInt("booth_id"));
                            list.add(mCollection);
                        }
                    }
                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                my_product_liuyan_BGARefreshLayout.endRefreshing();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_qiye_liuyan_data_more() {
        page++;
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("page", page);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_qiye_liuyan,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        if (array.length() == 0) {
                            Toast.makeText(Main_My_product_liuyanActivity.this, "没有更多数据哦", Toast.LENGTH_SHORT).show();
                            my_product_liuyan_BGARefreshLayout.endLoadingMore();
                        } else {
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject obj = array.getJSONObject(i);
                                Collection mCollection = new Collection();
                                mCollection.setTitle(obj.getJSONObject("booths").getString("title"));
                                mCollection.setCreated_at(obj.getString("created_at"));
                                mCollection.setDetail(obj.getString("detail"));
                                mCollection.setNickname(obj.getJSONObject("other").getString("nickname"));
                                mCollection.setId(obj.getInt("booth_id"));
                                list.add(mCollection);
                            }
                        }
                        handler.sendEmptyMessage(2);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                my_product_liuyan_BGARefreshLayout.endLoadingMore();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 企业账号：我收到的服务留言
     */
    public void get_myreceiver_fuwu_liuyan_data() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("page", 1);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_receiver_fuwu_liuyan,
                params, new Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {

                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            Collection mCollection = new Collection();
                            mCollection.setTitle(obj.getJSONObject("boothscase").getString("title"));
                            mCollection.setCreated_at(obj.getString("created_at"));
                            mCollection.setDetail(obj.getString("detail"));
                            mCollection.setNickname(obj.getJSONObject("usrs").getString("nickname"));
                            mCollection.setId(obj.getJSONObject("boothscase").getInt("id"));
                            list.add(mCollection);
                        }
                    }
                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                my_product_liuyan_BGARefreshLayout.endRefreshing();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_myreceiver_fuwu_liuyan_data_more() {
        page++;
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("page", page);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_receiver_fuwu_liuyan,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        if (array.length() == 0) {
                            Toast.makeText(Main_My_product_liuyanActivity.this, "没有更多数据哦", Toast.LENGTH_SHORT).show();
                            my_product_liuyan_BGARefreshLayout.endLoadingMore();
                        } else {
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject obj = array.getJSONObject(i);
                                Collection mCollection = new Collection();
                                mCollection.setTitle(obj.getJSONObject("boothscase").getString("title"));
                                mCollection.setCreated_at(obj.getString("created_at"));
                                mCollection.setDetail(obj.getString("detail"));
                                mCollection.setNickname(obj.getJSONObject("usrs").getString("nickname"));
                                mCollection.setId(obj.getJSONObject("boothscase").getInt("id"));
                                list.add(mCollection);
                            }
                        }
                        handler.sendEmptyMessage(2);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                my_product_liuyan_BGARefreshLayout.endLoadingMore();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 企业账号：我收到的店铺留言
     */
    public void get_myreceiver_qiye_liuyan_data() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("page", 1);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_receiver_qiye_liuyan,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            Collection mCollection = new Collection();
                            mCollection.setTitle(obj.getJSONObject("booths").getString("title"));
                            mCollection.setCreated_at(obj.getString("created_at"));
                            mCollection.setDetail(obj.getString("detail"));
                            mCollection.setNickname(obj.getJSONObject("usrs").getString("nickname"));
                            mCollection.setId(obj.getJSONObject("booths").getInt("id"));
                            list.add(mCollection);
                        }
                    }
                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                my_product_liuyan_BGARefreshLayout.endRefreshing();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_myreceiver_qiye_data_more() {
        page++;
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("page", page);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_receiver_qiye_liuyan,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        if (array.length() == 0) {
                            Toast.makeText(Main_My_product_liuyanActivity.this, "没有更多数据哦", Toast.LENGTH_SHORT).show();
                            my_product_liuyan_BGARefreshLayout.endLoadingMore();
                        } else {
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject obj = array.getJSONObject(i);
                                Collection mCollection = new Collection();
                                mCollection.setTitle(obj.getJSONObject("booths").getString("title"));
                                mCollection.setCreated_at(obj.getString("created_at"));
                                mCollection.setDetail(obj.getString("detail"));
                                mCollection.setNickname(obj.getJSONObject("usrs").getString("nickname"));
                                mCollection.setId(obj.getJSONObject("booths").getInt("id"));
                                list.add(mCollection);
                            }
                        }
                        handler.sendEmptyMessage(2);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                my_product_liuyan_BGARefreshLayout.endLoadingMore();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 企业账号：我收到的产品留言
     */
    public void get_myreceiver_product_liuyan_data() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("page", 1);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_receiver_product_liuyan,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            Collection mCollection = new Collection();
                            mCollection.setTitle(obj.getJSONObject("boothsproduct").getString("title"));
                            mCollection.setCreated_at(obj.getString("created_at"));
                            mCollection.setDetail(obj.getString("detail"));
                            mCollection.setNickname(obj.getJSONObject("usrs").getString("nickname"));
                            mCollection.setId(obj.getJSONObject("boothsproduct").getInt("id"));
                            list.add(mCollection);
                        }
                    }
                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                my_product_liuyan_BGARefreshLayout.endRefreshing();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_myreceiver_product_data_more() {
        page++;
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("page", page);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.my_receiver_product_liuyan,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        if (array.length() == 0) {
                            Toast.makeText(Main_My_product_liuyanActivity.this, "没有更多数据哦", Toast.LENGTH_SHORT).show();
                            my_product_liuyan_BGARefreshLayout.endLoadingMore();
                        } else {
                            for (int i = 0; i < array.length(); i++) {
                                JSONObject obj = array.getJSONObject(i);
                                Collection mCollection = new Collection();
                                mCollection.setTitle(obj.getJSONObject("boothsproduct").getString("title"));
                                mCollection.setCreated_at(obj.getString("created_at"));
                                mCollection.setDetail(obj.getString("detail"));
                                mCollection.setNickname(obj.getJSONObject("usrs").getString("nickname"));
                                mCollection.setId(obj.getJSONObject("boothsproduct").getInt("id"));
                                list.add(mCollection);
                            }
                        }
                        handler.sendEmptyMessage(2);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                my_product_liuyan_BGARefreshLayout.endLoadingMore();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }
}
